$(function () {
	if (url('entname')) {
		vm.q.entname = url('entname');
        vm.getDetails();
	} 
	var page = 1;
    if (localStorage.getItem("page1")) {
    	page = localStorage.getItem("page1");
        localStorage.removeItem("page1");
	} 
    $("#jqGrid").jqGrid({
        url: baseURL + 'ccbusiness/cregisterinfo/listcompany',
        datatype: "json",
        postData: {
        	'entname': vm.q.entname
        },
        page:page,
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true ,hidden: true},
			{ label: '企业名称', name: 'entname', index: 'entname', width: 100 }, 			
//			{ label: '曾用名', name: 'oldname', index: 'oldname', width: 80 }, 			
//			{ label: '统一社会信用代码', name: 'shxydm', index: 'shxydm', width: 80 }, 			
			{ label: '法定代表人', name: 'frdb', index: 'frdb', width: 40 }, 			
			{ label: '成立日期', name: 'esdate', index: 'esdate', width: 60 }, 			
			{ label: '经营状态', name: 'entstatus', index: 'entstatus', width: 80 }, 			
			{ label: '注册资本（万元）', name: 'regcap', index: 'regcap', width: 60 }, 			
//			{ label: '注册资本币种', name: 'regcapcur', index: 'regcapcur', width: 80 }, 			
//			{ label: '地址', name: 'dom', index: 'dom', width: 80 }, 			
			{ label: '企业类型', name: 'enttype', index: 'enttype', width: 80 }, 			
//			{ label: '经营业务范围', name: 'opscope', index: 'opscope', width: 80 }, 			
//			{ label: '登记机关', name: 'regorg', index: 'regorg', width: 80 }, 			
//			{ label: '经营期限自', name: 'opfrom', index: 'opfrom', width: 80 }, 			
//			{ label: '经营期限至', name: 'opto', index: 'opto', width: 80 }, 			
//			{ label: '核准日期', name: 'apprdate', index: 'apprdate', width: 80 }, 			
//			{ label: '死亡日期', name: 'enddate', index: 'enddate', width: 80 }, 			
//			{ label: '吊销日期', name: 'revdate', index: 'revdate', width: 80 }, 			
//			{ label: '注销日期', name: 'candate', index: 'candate', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
    
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		q:{
			entname: null,
			frdb: '',
			regcap: '',
			enttype: '',
        },
		showList: true,
		title: null,
		holderList : [],
		entChronicleInfoList : [],
        showGraph:{
			data: [{
                name: '企业数据',
                x: 50,
                y: 50
            }, {
                name: '项目库数据',
                x: 150,
                y: 50
            }, {
                name: '本地资源',
                x: 250,
                y: 50
            }, {
                name: '鼓励类政策/限制类政策/禁止类政策/临时变动政策',
                x: 100,
                y: 100
            }, {
                name: '产业链条上的资源整合/需求整合',
                x: 200,
                y: 100
            }, {
                name: '项目资源优势',
                x: 300,
                y: 100
            }, {
                name: '推荐项目',
                x: 350,
                y: 50
            }],
            links: [{
                source: 0,
                target: 1
            },{
                source: 1,
                target: 2
            },{
                source: 2,
                target: 6
            },{
                source: 3,
                target: 2
            },{
                source: 4,
                target: 2
            },{
                source: 5,
                target: 2
            }],
		},
		cRegisterinfo: {}
	},
	methods: {
		query: function () {
            $("#jqGrid").setGridParam({'page': 1});
			vm.reload();
		},
		details: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "详情";
            vm.getInfo(id)
		},
		getDetails: function () {
			vm.showList = false;
            vm.title = "详情";
            $.get(baseURL + "ccbusiness/cregisterinfo/infobyname/"+vm.q.entname, function(r){
                vm.cRegisterinfo = r.cRegisterinfo;
                vm.holderList = r.holderList;
                vm.entChronicleInfoList = r.entChronicleInfoList;
            });
		},
		showrecproject: function (event) {
            var id = getSelectedRow();
            if (id == null) {
                return;
            }
    		localStorage.setItem("page1", $('#jqGrid').getGridParam('page'));
            window.location.href = 'recommendprojects2.html?id=' + id;
        },
		getInfo: function(id){
			$.get(baseURL + "ccbusiness/cregisterinfo/info/"+id, function(r){
                vm.cRegisterinfo = r.cRegisterinfo;
                vm.holderList = r.holderList;
                vm.entChronicleInfoList = r.entChronicleInfoList;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                postData: vm.q,
                page:page
            }).trigger("reloadGrid");
		}
	}
});